<template>
	<view>
		<view class="tour-box" v-if="marker.length>0">
			<map :style="'width:100%;height:'+height+'px'" :latitude="latitude" :longitude="longitude" :markers="marker"
				:scale="scale" @markertap="goDetail"></map>
		</view>
	</view>
</template>

<script>
  import {position_list} from "../../../common/api/map";
	export default {
		data() {
			return {
        latitude: 31.706880256689402,
        longitude: 120.76519555673588,
				marker: [],
				height: 0,
				scale: 14
			}
		},
		onLoad() {
			uni.showLoading({
				title: "组件渲染中..."
			})
			const sysInfo = uni.getSystemInfoSync()
			this.height = sysInfo.screenHeight
			this.getData()
		},
		methods: {
			goDetail(e) {
        // console.log('map--index--goDetail', e);
        const _position_list = uni.getStorageSync('position_list')
        // console.log('eeeeeeee', _position_list);
        let _audit_status = []
        if (_position_list.length > 0) {
          _audit_status = _position_list.filter(item => item.content_id === e.markerId)
        }
        this.$Router.push({
          name: 'myPaiAndFb',
          data: {
            content_id: e.markerId,
            audit_status: _audit_status[0]
          }
        })
			},
      getData () {
        const _userInfo = uni.getStorageSync('_userInfo')
        position_list({submit_user_id: _userInfo.admin_user_id}).then(res => {
          // console.log('position_list---', res)
          if (res.length > 0)
            uni.setStorageSync('position_list', res)

          let marker = []
          res.forEach(item=> {
            marker.push({
              id: item.content_id,
              longitude: item.longitude,
              latitude: item.latitude,
              rotate: 0, // 旋转度数
              width: 20, //宽
              height: 30, //高
              //title: res[0].name, //标注点名
              alpha: 1, //透明度
              label: { //为标记点旁边增加标签   //因背景颜色H5不支持
                content: item.name, //文本
                color: '#fff', //文本颜色
                fontSize: 12, //文字大小
                anchorX: 0, //label的坐标，原点是 marker 对应的经纬度
                anchorY: 5, //label的坐标，原点是 marker 对应的经纬度
                borderWidth: 0, //边框宽度
                borderColor: 'pink', //边框颜色
                borderRadius: 5, //边框圆角
                // bgColor: "#1bcb9d", //背景色
                bgColor: "#2979ff", //背景色
                padding: 5, //文本边缘留白
                textAlign: 'center' //文本对齐方式。
              }
            })
          })
          this.marker = marker
          setTimeout(function(){
            uni.hideLoading();
          },1000)
        })
      }
		}
	}
</script>

<style>
</style>
